import json
from openpyxl import Workbook
import datetime
hears = []

with open(r'D:\电子证照云南\黄剑20241031破解建行证照系统目录数据接口\new 1.txt', 'r', encoding= 'UTF-8') as file:
    result_str = eval(file.read())
    result_dict = json.loads(result_str)
    result_body = json.loads(result_dict['C-Response-Body'])
    global result_com
    result_com = result_body['txnBodyCom']
    for key in result_com[0].keys():
        hears.append(key)



# 创建一个excel
wb = Workbook()

# 获取当前使用的sheet
sheet = wb.active
for i in range(0,len(hears)):
    sheet.cell(row=1, column=i + 1).value = hears[i]


row = 1
for result in result_com:
    row += 1
    col = 1
    for head in hears:
        if head == 'updateDate' or head == 'createDate':
            try:
                sheet.cell(row=row, column=col).value = str(datetime.datetime.fromtimestamp(int(result[head] / 1000)))
            except:
                sheet.cell(row=row, column=col).value = str(result[head])

        else:
            sheet.cell(row=row, column=col).value = str(result[head])
        col += 1


wb.save( r'D:\电子证照云南\黄剑20241031破解建行证照系统目录数据接口\my.xlsx')